home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1458.dms / var1458.adf / IDCMP / Example7.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  6KB  |  180 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: IDCMP                       Tulevagen 22       */
  8. /* File:    Example7.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This program explains how to use the IDCMP flags: DISKINSERTED and */
  21. /* DISKREMOVED.                                                       */
  22.  
  23.  
  24.  
  25. #include <intuition/intuition.h>
  26.  
  27.  
  28.  
  29. struct IntuitionBase *IntuitionBase;
  30.  
  31.  
  32.  
  33. /* Declare a pointer to a Window structure: */ 
  34. struct Window *my_window;
  35.  
  36. /* Declare and initialize your NewWindow structure: */
  37. struct NewWindow my_new_window=
  38. {
  39.   50,             /* LeftEdge    x position of the window. */
  40.   25,             /* TopEdge     y positio of the window. */
  41.   320,            /* Width       320 pixels wide. */
  42.   100,            /* Height      100 lines high. */
  43.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  44.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  45.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user */
  46.                   /*             selects the Close window gad.           */
  47.  
  48.   DISKINSERTED|   /*             We will also recieve a message whenever */
  49.   DISKREMOVED,    /*             a disk is inserted or removed.          */
  50.  
  51.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  52.   WINDOWCLOSE|    /*             Close Gadget. */
  53.   WINDOWDRAG|     /*             Drag gadget. */
  54.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  55.   WINDOWSIZING|   /*             Sizing Gadget. */
  56.   ACTIVATE,       /*             The window should be Active when opened. */
  57.   NULL,           /* FirstGadget No gadgets connected to this window. */
  58.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  59.   "TOUCH MY DISKS",/* Title      Title of the window. */
  60.   NULL,           /* Screen      Connected to the Workbench Screen. */
  61.   NULL,           /* BitMap      No Custom BitMap. */
  62.   100,            /* MinWidth    We will not allow the window to become */
  63.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  64.   400,            /* MaxWidth    than 400 x 200. */
  65.   200,            /* MaxHeight */
  66.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  67. };
  68.  
  69.  
  70.  
  71. /**************************************************************************/
  72. /* Extra information:                                                     */
  73. /* The IDCMP messages DISKINSERTED and DISKREMOVED can not be "swollowed" */
  74. /* by a program. All applications will hear about it if they want. This   */
  75. /* is the opposite of other IDCMP flags which will be "swollowed" by the  */
  76. /* active window's program.                                               */
  77. /**************************************************************************/
  78.  
  79.  
  80.  
  81. main()
  82. {
  83.   /* Boolean variable used for the while loop: */
  84.   BOOL close_me;
  85.  
  86.   ULONG class; /* IDCMP flag. */
  87.  
  88.   /* Pointer to an IntuiMessage structure: */
  89.   struct IntuiMessage *my_message;
  90.  
  91.  
  92.  
  93.   /* Before we can use Intuition we need to open the Intuition Library: */
  94.   IntuitionBase = (struct IntuitionBase *)
  95.     OpenLibrary( "intuition.library", 0 );
  96.   
  97.   if( IntuitionBase == NULL )
  98.     exit(); /* Could NOT open the Intuition Library! */
  99.  
  100.  
  101.  
  102.   /* We will now try to open the window: */
  103.   my_window = (struct Window *) OpenWindow( &my_new_window );
  104.   
  105.   /* Have we opened the window succesfully? */
  106.   if(my_window == NULL)
  107.   {
  108.     /* Could NOT open the Window! */
  109.     
  110.     /* Close the Intuition Library since we have opened it: */
  111.     CloseLibrary( IntuitionBase );
  112.  
  113.     exit();  
  114.   }
  115.  
  116.  
  117.  
  118.   /* We have opened the window, and everything seems to be OK. */
  119.  
  120.   printf("Insert or remove a disk!\n\n");
  121.  
  122.  
  123.  
  124.   close_me = FALSE;
  125.  
  126.   /* Stay in the while loop until the user has selected the Close window */
  127.   /* gadget: */
  128.   while( close_me == FALSE )
  129.   {
  130.     /* Wait until we have recieved a message: */
  131.     Wait( 1 << my_window->UserPort->mp_SigBit );
  132.  
  133.  
  134.     /* As long as we can collect messages successfully we stay in the */
  135.     /* while-loop: */
  136.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  137.     {
  138.       /* After we have successfully collected the message we can read */
  139.       /* it, and save any important values which we maybe want to check */
  140.       /* later: */
  141.       class = my_message->Class;         /* IDCMP flag. */
  142.  
  143.  
  144.       /* After we have read it we reply as fast as possible: */
  145.       /* REMEMBER! Do never try to read a message after you have replied! */
  146.       /* (Some other process has maybe changed it.) */
  147.       ReplyMsg( my_message );
  148.  
  149.  
  150.       /* Check which IDCMP flag was sent: */
  151.       switch( class )
  152.       {
  153.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  154.                close_me=TRUE;
  155.                break;
  156.  
  157.         case DISKINSERTED:   /* The user inserted a disk in a drive. */
  158.                printf("Disk inserted!\n");
  159.                break;
  160.  
  161.         case DISKREMOVED:    /* The user removed a disk from a drive. */
  162.                printf("Disk removed!\n");
  163.                break;
  164.       }
  165.     }
  166.   }
  167.  
  168.  
  169.  
  170.   /* Close the window: */
  171.   CloseWindow( my_window );
  172.  
  173.  
  174.  
  175.   /* Close the Intuition Library: */
  176.   CloseLibrary( IntuitionBase );
  177.   
  178.   /* THE END */
  179. }
  180.